package com.insurance.util;

public class PageBean {
	
	public PageBean() {
		
	}

	private int totalcount = 0;
	
	private int currentpage = 1;
	
	private int totalpages = 0;
	
	private int pagesize = 10;

	public int getTotalcount() {
		return totalcount;
	}

	public void setTotalcount(int totalcount) {
		this.totalcount = totalcount;
		this.setTotalpages(totalcount % pagesize == 0 ? totalcount / pagesize : totalcount / pagesize + 1);
		resetCurrentpage();
	}

	public int getCurrentpage() {
		return currentpage;
	}

	public void setCurrentpage(int currentpage) {
		this.currentpage = currentpage;
	}

	public int getTotalpages() {
		return totalpages;
	}

	public void setTotalpages(int totalpages) {
		this.totalpages = totalpages;
	}

	public int getPagesize() {
		return pagesize;
	}

	public void setPagesize(int pagesize) {
		this.pagesize = pagesize;
	}
	
	public static int perpage = 10;

	public PageBean(int totalcount, int currentpage, int pagesize) {
		this.setCurrentpage(currentpage);
		this.setPagesize(pagesize);
		this.setTotalcount(totalcount);
	}
	
	public void resetCurrentpage(){
		if(this.getCurrentpage() < 1){
			this.setCurrentpage(1);
		}
		if(this.getCurrentpage() > this.getTotalpages()){
			this.setCurrentpage(this.getTotalpages() <= 0 ? 1 : this.getTotalpages());
		}
	}

}
